package edu.fanhuiling.blogsystem.mapper;

import edu.fanhuiling.blogsystem.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface BlogInfoMapper {
    /*
    * 获取博客列表
    * */
    @Select("select * from blog where delete_flag=0 order by create_time desc")
    List<BlogInfo> getBlogList();
    /*
    *
    * 根据博客id,获取博客详情
    * */
    @Select("select * from blog where id=#{id} and delete_flag=0")
    BlogInfo getDetailById(Integer id);






    /*
    *
    * 根据博客id,编辑博客
    * */
    @Update("update blog set title=#{title},content=#{content} where id=#{id} and delete_flag=0")
    Integer editBlog(BlogInfo blogInfo);


    /*
    *
    * 根据博客id,删除博客,逻辑删除
    * */
    @Update("update blog set delete_flag=1 where id=#{id}")
    Integer deleteBlog(Integer id);

    /*
    *
    * 根据输入的内容，添加博客
    * */
    @Insert("insert into blog (title,content,user_id) values (#{title},#{content},#{userId})")
    Integer addBlog(BlogInfo blogInfo);
}
